class Solution(object):
    def licenseKeyFormatting(self, s, k):
        """
        :type s: str
        :type k: int
        :rtype: str
        """
        s = s.upper()
        s = s.split('-')
        s = ''.join(s)
        n = len(s)
        m = n % k
        t = n // k
        c = s[:m]
        for i in range(t):
            c += '-'
            c += s[m + i * k: m + (i + 1) * k]
        if m > 0:
            return c
        else:
            return c[1:]


data = Solution()
s = "5F3Z-2e-9-w"
k = 4
print(data.licenseKeyFormatting(s, k))
